package com.gonsin.gnews.annotations.model;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@Data
public class GNewsPageResult<T> {

    @ApiModelProperty("列表数据")
    private List<T> data;

    @ApiModelProperty("页数")
    private int pageCount = -1;

    @ApiModelProperty("当前页码")
    private int page = -1;

    @ApiModelProperty("每页数量")
    private int count;

    @ApiModelProperty("总数量")
    private int totalCount;

    public static <D> GNewsPageResult<D> result(List<D> data, int totalCount, GNewsPageRequest pageRequest) {
        GNewsPageResult<D> result = new GNewsPageResult();
        result.setData(data);
        result.setTotalCount(totalCount);
        result.setPage(pageRequest.getPage());
        result.setCount(pageRequest.getCount());
        result.setPageCount(totalCount / pageRequest.getCount() + 1);
        return result;
    }

}
